package cn.sciento.farm.devicemanager.gateway.model.downlink.fertilizer;

import cn.sciento.farm.devicemanager.common.constant.MqttConstant;
import cn.sciento.farm.devicemanager.gateway.model.downlink.AbstractBlockData;
import cn.sciento.farm.devicemanager.gateway.model.downlink.MqttContent;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = false)
public class FertilizerMainData extends AbstractBlockData {

    private String eui;

    private Integer modbusAddr ;

    private Integer fertilizeTime;

    private Integer mainControl;

    @Override
    public String generateId() {
        return String.format(MqttConstant.FERTILIZER_CONTROL_MAIN_BLOCK_ID, this.eui);

    }

    @Override
    public String generateStatus() {
        return null;
    }

    @Override
    public MqttContent generate() {
        String topic = String.format(MqttConstant.FERTILIZER_DOWN_TOPIC, this.eui);
        Map map = new HashMap<String,Object>();
        map.put("id",modbusAddr);
        map.put("channel",0);
        map.put("fertilizeTime",fertilizeTime);
        map.put("mainControl",mainControl);
        String payload = JSON.toJSONString(map);
        return new MqttContent(topic,payload);
    }
}
